﻿using System;
using System.Collections.Generic;
using UnityEngine;
using System.Text;

public class EnergySystem : IGameSystem
{
    private const int MAX_Energy = 100;

    // 当前能量(开始是满的)
    private float mNowEnergy = MAX_Energy;

    // 能量恢复速度
    private float mRecoverSpeed = 3;

    public override void Init() { base.Init(); }

    public override void Update()
    {
        base.Update();
        // 一上来就需要显示准确的能量值,更新到UI
        GameFacade.Instance.UpdateEnergySlider((int) mNowEnergy, MAX_Energy);
        if (mNowEnergy >= MAX_Energy) return; //能量满了就不再恢复
        mNowEnergy += mRecoverSpeed * Time.deltaTime;
        //if (mNowEnergy > MAX_Energy)
        //{
        //    mNowEnergy = MAX_Energy;
        //} // 这里用Mathf.Min来代替
        mNowEnergy = Mathf.Min(mNowEnergy, MAX_Energy);
        // GameFacade.Instance.UpdateEnergySlider((int)mNowEnergy, MAX_Energy);
    }

    // 能否消耗值为value能量
    public bool TakeEnergy(int value)
    {
        if (mNowEnergy >= value)
        {
            mNowEnergy -= value;
            return true;
        }

        return false;
    }

    // 回收能量??
    public void RecycleEnergy(int value)
    {
        mNowEnergy += value;
        mNowEnergy = Mathf.Min(mNowEnergy, MAX_Energy);
    }
}